package com.gzx.bi.modular.goals.monthly.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gzx.bi.modular.goals.monthly.entity.GzxGoalsLineChartVo;
import com.gzx.bi.modular.goals.monthly.entity.bo.GzxMonthlyGoalsAddOrEditBo;
import com.gzx.bi.modular.goals.monthly.entity.bo.GzxMonthlyGoalsQueryBo;
import com.gzx.bi.modular.goals.monthly.entity.vo.GzxCommissionRatioListVo;
import com.gzx.bi.modular.goals.monthly.entity.vo.GzxMonthlyGoalsVo;
import com.gzx.bi.modular.goals.monthly.service.GzxMonthlyGoalsService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import vip.xiaonuo.common.annotation.CommonLog;
import vip.xiaonuo.common.pojo.CommonResult;

import java.util.List;

/**
 * @author zjt
 * @description
 * @date 2025/1/13 14:01
 */
@RequiredArgsConstructor
@RestController
@RequestMapping("/bi/goals/monthly")
public class GzxMonthlyGoalsController {

    private final GzxMonthlyGoalsService monthlyGoalsService;

    /**
     * 获取案件详情页分案记录
     *
     * @param monthlyGoalsQueryBo 查询条件
     * @return
     */
    @PostMapping("/pageList")
    public CommonResult<Page<GzxMonthlyGoalsVo>> pageList(@RequestBody GzxMonthlyGoalsQueryBo monthlyGoalsQueryBo) {
        return CommonResult.data(monthlyGoalsService.pageList(monthlyGoalsQueryBo));
    }

    /**
     * 获取案件详情页分案记录
     *
     * @param belongingMonth 查询条件
     * @return
     */
    @GetMapping("/list/{belongingMonth}")
    public CommonResult<List<GzxMonthlyGoalsVo>> list(@PathVariable("belongingMonth") Integer belongingMonth) {
        return CommonResult.data(monthlyGoalsService.list(belongingMonth));
    }

    /**
     * 获取案件详情页分案记录
     *
     * @param monthlyGoalsAddOrEditBo 查询条件
     * @return
     */
    @PostMapping("/add")
    public CommonResult<Page<GzxMonthlyGoalsVo>> add(@RequestBody GzxMonthlyGoalsAddOrEditBo monthlyGoalsAddOrEditBo) {
        monthlyGoalsService.add(monthlyGoalsAddOrEditBo);
        return CommonResult.ok();
    }

    /**
     * 获取案件详情页分案记录
     *
     * @param monthlyGoalsAddOrEditBo 查询条件
     * @return
     */
    @PostMapping("/edit")
    public CommonResult<Page<GzxMonthlyGoalsVo>> edit(@RequestBody GzxMonthlyGoalsAddOrEditBo monthlyGoalsAddOrEditBo) {
        monthlyGoalsService.edit(monthlyGoalsAddOrEditBo);
        return CommonResult.ok();
    }

    /**
     * 添加佣金比例明细
     * @param json
     * @return
     */
    @CommonLog("添加佣金比例明细")
    @PostMapping("/addRetaio")
    public CommonResult<String> addRatio(@RequestBody String json,@RequestParam("id") Long id) {
        monthlyGoalsService.addRatio(json,id);
        return CommonResult.ok();
    }

    /**
     * 添加佣金比例明细
     * @param
     * @return
     */
    @CommonLog("获取佣金比例明细")
    @PostMapping("/pageListRatio")
    public CommonResult<List<GzxCommissionRatioListVo>> pageListRatio(@RequestBody  GzxMonthlyGoalsAddOrEditBo monthlyGoalsAddOrEditBo ) {
        List<GzxCommissionRatioListVo> gzxCommissionRatioListVos = monthlyGoalsService.pageListRatio(monthlyGoalsAddOrEditBo);
        return CommonResult.data(gzxCommissionRatioListVos);
    }


    /**
     * 获取案件详情页分案记录
     *
     * @param id 查询条件
     * @return
     */
    @GetMapping("/getChartData/{id}")
    public CommonResult<List<GzxGoalsLineChartVo>> getChartData(@PathVariable("id") Long id) {
        return CommonResult.data(monthlyGoalsService.getChartData(id));
    }

    /**
     * 初始化本月的数据
     * @return
     */
    @CommonLog("初始化本月的数据")
    @PostMapping("/initialize")
    public CommonResult<String> initialize(@RequestBody GzxMonthlyGoalsAddOrEditBo monthlyGoalsAddOrEditBo) {
        Long id = monthlyGoalsAddOrEditBo.getId();
        monthlyGoalsService.initialize(id);
        return CommonResult.ok();
    }

}
